/*     */ package com.lmpop.frame.util;
/*     */ 
/*     */ import java.io.BufferedReader;
/*     */ import java.io.File;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStreamReader;
/*     */ import java.io.PrintStream;
/*     */ import java.sql.Connection;
/*     */ import java.sql.PreparedStatement;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Properties;
/*     */ 
/*     */ public class InitSQLClass
/*     */ {
/*     */   private String sqlFile;
/*     */   private Config config;
/*  27 */   List<String> sqlFileList = new ArrayList();
/*     */ 
/*     */   public InitSQLClass()
/*     */   {
/*  23 */     this.config = new Config();
/*  24 */     this.config.init("config.properties");
/*  25 */     this.sqlFile = (this.config.getString("rootpath") + this.config.getString("sqlFile"));
/*     */   }
/*     */ 
/*     */   public List<String> readSqlFile(String new_encoding, String database) {
/*  29 */     List sqlList = new ArrayList();
/*  30 */     File myFile = new File(this.sqlFile);
/*  31 */     if (!myFile.exists()) {
/*  32 */       System.err.println("Can't Find " + this.sqlFile);
/*  33 */       return null;
/*     */     }
/*  35 */     StringBuffer temp = new StringBuffer();
/*     */     try {
/*  37 */       BufferedReader in = null;
/*  38 */       if (!System.getProperties().getProperty("file.encoding").equals("UTF-8"))
/*  39 */         in = new BufferedReader(new InputStreamReader(new FileInputStream(this.sqlFile), "UTF-8"));
/*     */       else {
/*  41 */         in = new BufferedReader(new InputStreamReader(new FileInputStream(this.sqlFile)));
/*     */       }
/*     */ 
/*  44 */       int index = 1;
/*     */       String str;
/*  45 */       while ((str = in.readLine()) != null) {
/*  46 */         if ((index == 18) || (index == 20)) {
/*  47 */           if (this.config.getString("sqlFile").indexOf("zl_framedev-group") != -1) {
/*  48 */             str = str.replace("zl_groupdev", database);
/*     */           }
/*  50 */           if (this.config.getString("sqlFile").indexOf("zl_framedev-b2c") != -1) {
/*  51 */             str = str.replace("zl_b2cdev", database);
/*     */           }
/*     */         }
/*     */ 
/*  55 */         temp.append(str.replaceAll("gbk", new_encoding));
/*  56 */         index++;
/*     */       }
/*  58 */       in.close();
/*     */     } catch (IOException e) {
/*  60 */       e.getStackTrace();
/*     */     }
/*  62 */     String[] sqls = temp.toString().split(";");
/*  63 */     for (String sql : sqls) {
/*  64 */       sqlList.add(sql);
/*     */     }
/*     */ 
/*  67 */     return sqlList;
/*     */   }
/*     */ 
/*     */   public void execSQL(List<String> sqlList, Connection connection)
/*     */   {
/*  72 */     if (connection == null) {
/*  73 */       System.out.println("不能打开连接");
/*  74 */       return;
/*     */     }
/*  76 */     PreparedStatement pstmt = null;
/*     */     try {
/*  78 */       for (String sql : sqlList) {
/*  79 */         pstmt = connection.prepareStatement(sql, 1004, 1007);
/*  80 */         pstmt.execute();
/*     */       }
/*  82 */       pstmt.close();
/*  83 */       connection.close();
/*     */     } catch (SQLException e) {
/*     */       try {
/*  86 */         pstmt.close();
/*  87 */         connection.close();
/*     */       } catch (SQLException e1) {
/*  89 */         e1.printStackTrace();
/*     */       }
/*     */ 
/*  92 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void execSQLByFile(String sqlfile, Connection connection) {
/*  97 */     File myFile = new File(sqlfile);
/*  98 */     if (!myFile.exists()) {
/*  99 */       System.err.println("Can't Find " + sqlfile);
/* 100 */       return;
/*     */     }
/* 102 */     StringBuffer temp = new StringBuffer();
/*     */     try {
/* 104 */       BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(sqlfile), "UTF-8"));
/*     */       String str;
/* 106 */       while ((str = in.readLine()) != null) {
/* 107 */         temp.append(str);
/*     */       }
/* 109 */       in.close();
/*     */     } catch (IOException e) {
/* 111 */       e.getStackTrace();
/*     */     }
/* 113 */     if (connection == null) {
/* 114 */       System.out.println("不能打开连接");
/* 115 */       return;
/*     */     }
/* 117 */     PreparedStatement pstmt = null;
/*     */     try {
/* 119 */       pstmt = connection.prepareStatement(temp.toString(), 1004, 1007);
/* 120 */       pstmt.execute();
/* 121 */       pstmt.close();
/* 122 */       connection.close();
/*     */     } catch (SQLException e) {
/*     */       try {
/* 125 */         pstmt.close();
/* 126 */         connection.close();
/*     */       } catch (SQLException e1) {
/* 128 */         e1.printStackTrace();
/*     */       }
/*     */ 
/* 131 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ }

/* Location:           F:\电商\commons-utils.jar
 * Qualified Name:     com.lmpop.frame.util.InitSQLClass
 * JD-Core Version:    0.6.0
 */